<?php 

require 'views/costum/match.php';

if ($view->user->invisible) {
	echo '<p class="highlight">
			You are invisible: others can\'t see your profile and you 
			can\'t send or receive messages. To change this, go to "Profile & preferences".
		  </p>
	';
}

// If user has rejected the candidate already, he/she is shown separately from the oter candidates
$candidates = array();
$rejections = array();
foreach ($view->matches as $match) {
	if (in_array($match->user_id, $view->user->rejections)) {
		$rejections[] = $match;
	}
	else {
		$candidates[] = $match;
	}
}

if (count($candidates) > 0) { 
	echo "<p>These profiles match yours:</p>";
}
else { 
	/* Check again later,
			or turn on email alerts in the preferences tab, so that you get notified
			if a matching partner registers!*/
	echo "<p>
			There are no matching partners for you yet (keep in mind that 
			this website has just been launched!). Please check again later.
		  </p>
	";
}

echo "<div>";
foreach($candidates as $match) {
	echo_match($view->user, $match);
}
echo "</div>";


if ($rejections) { ?>
	<p class='vague'>
	<?php 
	if (count($rejections) == 1) {
		echo '1 rejected matching partner is hidden'; 
	}
	else {
		echo count($rejections) . ' rejected matching partners are hidden'; 
	}
	?>
	(<a href='#' id='toggle_rejected' class='toggle'>show</a>)
	<script type='text/javascript'>
		$('#toggle_rejected').click(function() {
			if ($('#toggle_rejected').text() == 'show') {
				$('#rejected').slideDown();
				$('#toggle_rejected').text('hide');
			}
			else {
				$('#rejected').slideUp();
				$('#toggle_rejected').text('show');
			} 
			return false;
		});
	</script>
	</p>	
	<div id='rejected'><?php 
		foreach($rejections as $match) {
			echo_match($view->user, $match);
		}
	?></div><?php
}
?>